<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改问题')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-dfQuestion-edit" th:object="${dfQuestion}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<div class="form-group">	
				<label class="col-sm-3 control-label">用户名称：</label>
				<div class="col-sm-8">
					<input id="userName" name="userName" th:field="*{userName}" class="form-control" type="text" readonly>
				</div>
			</div>
			<div class="form-group" style="display: none">
				<label class="col-sm-3 control-label">用户id：</label>
				<div class="col-sm-8">
					<input id="userId" name="userId" th:field="*{userId}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">用户单位：</label>
				<div class="col-sm-8">
					<input id="userDept" name="userDept" th:field="*{userDept}" class="form-control" type="text" readonly>
				</div>
			</div>
			<div class="form-group" style="display: none">
				<label class="col-sm-3 control-label">用户单位id：</label>
				<div class="col-sm-8">
					<input id="userDeptId" name="userDeptId" th:field="*{userDeptId}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group" style="display: none">
				<label class="col-sm-3 control-label">联系方式：</label>
				<div class="col-sm-8">
					<input id="userPhone" name="userPhone" th:field="*{userPhone}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group" style="display: none">
				<label class="col-sm-3 control-label">问题处理结果：</label>
				<div class="col-sm-8">
					<input id="questionState" name="questionState" th:field="*{questionState}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">问题类型：</label>
				<div class="col-sm-8" style="padding-top: 3px;">
					<select name="questionType" class="form-control">
						<option value="1">新需求</option>
						<option value="2">处理</option>
						<option value="3">解释</option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">问题标题：</label>
				<div class="col-sm-8">
					<input id="questionTitle" name="questionTitle" th:field="*{questionTitle}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">内容描述：</label>
				<div class="col-sm-8">
					<textarea id="questionContent" name="questionContent" th:field="*{questionContent}" class="form-control" rows="5" style="resize:none;"></textarea>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-8">
					<input id="questionStart" name="questionStart" class="form-control" type="hidden" th:field="*{questionStart}">
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-8">
					<input id="yjyApprove" name="yjyApprove" class="form-control" type="hidden" th:field="*{yjyApprove}">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">上传附件：</label>
				<div class="col-sm-8">
					<input type="file" accept="image/*" onchange="uploadFile()" id="fileUpload" multiple="multiple"/>
					<br><ul id="lid" style="padding-left: 0px;"><img src="" id="img0" ></ul>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "question/dfQuestion";
        var prefis = ctx + "question/dfFile"
        var preFile = "http://211.149.205.33:18080/file/";
        var id =$("#id").val(); //获取id
		$("#form-dfQuestion-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-dfQuestion-edit').serialize(),addFile);
	        }
	    }

        var arr =[];  //定义一个数组
	    //初始化图片
		$(function(){
            $.ajax({
                url:prefis+"/queryFileById?questionId="+id,
                type: "POST",
                cache: false,
                dataType:"json",
                contentType: false,
                processData: false,
                success: function(resp) {
                    if(resp.length > 0){
                        for(var i=0;i<resp.length;i++){
                            var model=new Object();
                            model.fileId =resp[i].fileId; //文件id
                            model.fileName =resp[i].fileName//文件名称

                            var suffix = resp[i].fileType;
                            model.fileType =suffix; //文件类型
                            arr.push(model);

                            if(suffix=="png" || suffix=="jpg"){
                                $("#lid").append('<img src="'+preFile+"img/"+190916001153798+'" id="img0" >').append(" ");
                            }
                            if(suffix=="xls" || suffix=="xlsx"){
                                $("#lid").append('<img src="'+preFile+"img/"+190916001140350+'" id="img0" >').append(" ");
                            }
                            if(suffix=="docx"|| suffix=="doc"){
                                $("#lid").append('<img src="'+preFile+"img/"+190916001206935+'" id="img0" >').append(" ");
                            }
                            if(suffix=="zip" || suffix=="rar"){
                                $("#lid").append('<img src="'+preFile+"img/"+190916001125877+'" id="img0" >').append(" ");
                            }
                            if(suffix=="ppt" || suffix=="pptx"){
                                $("#lid").append('<img src="'+preFile+"img/"+190916091106432+'" id="img0" >').append(" ");
                            }
						}
					}
				}
			})
		})

        function uploadFile(){		 //上传
            var file = $("#fileUpload").get(0).files[0];
            if(file != undefined){
                var formData = new FormData();
                formData.append("files", file);
                $.ajax({
                    url:preFile+"mulitiupload",
                    type: "POST",
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function(resp) {
                        var model=new Object();
                        model.fileId =resp[0].fileid; //文件id
                        model.fileName =resp[0].name;//文件名称
                        var index = model.fileName.lastIndexOf(".");
                        var suffix = model.fileName.substring(index+1);
                        model.fileType =suffix; //文件类型
                        arr.push(model);
                        if(suffix=="png" || suffix=="jpg"){
                            $("#lid").append('<img src="'+preFile+"img/"+190916001153798+'" id="img0" >').append(" ");
                        }
                        if(suffix=="xls" || suffix=="xlsx"){
                            $("#lid").append('<img src="'+preFile+"img/"+190916001140350+'" id="img0" >').append(" ");
                        }
                        if(suffix=="docx"|| suffix=="doc"){
                            $("#lid").append('<img src="'+preFile+"img/"+190916001206935+'" id="img0" >').append(" ");
                        }
                        if(suffix=="zip" || suffix=="rar"){
                            $("#lid").append('<img src="'+preFile+"img/"+190916001125877+'" id="img0" >').append(" ");
                        }
                        if(suffix=="ppt" || suffix=="pptx"){
                            $("#lid").append('<img src="'+preFile+"img/"+190916091106432+'" id="img0" >').append(" ");
                        }
                    },
                    error: function(error) {
                        $.modal.alertWarning("附件上传失败。");
                    }
                });
            } else {
                $.modal.alertWarning("服务出现错误 。联系管理员 ");
            }
        };

        function addFile(){
            $.ajax({
                url:prefis+"/editFile",
                type: "POST",
                data: {questionId:id,array:JSON.stringify(arr)},
                dataType:"json",
                success: function(resp) {
                }
            });
        }
	</script>
</body>
</html>
